package org.smart4j.chapter2.service;

import org.smart4j.chapter2.helper.DatabaseHelper;
import org.smart4j.chapter2.model.Customer;
import org.smart4j.chapter2.util.PropsUtil;

import java.io.IOException;
import java.net.URL;
import java.sql.*;
import java.util.*;


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class CustomerService {
    public static final Logger LOGGER =LoggerFactory.getLogger(CustomerService.class);

    //获取用户列表
    public List<Customer> getCustomerList(){
        String sql = "select * from customer";
        return DatabaseHelper.queryEntityList(Customer.class,sql);
    }
    //获取用户 by id
    public Customer getCustomer(long id){
        String sql="select * from customer where id=? ";
        return DatabaseHelper.queryEntity(Customer.class,sql,id);
    }
    //创建用户
    public boolean createCustomer(Map<String,Object> fieldMap){
        return DatabaseHelper.insertEntity(Customer.class,fieldMap);
    }

    //更新用户
    public boolean updateCustomer(long id ,Map<String,Object> fieldMap){
        return DatabaseHelper.updateEntity(Customer.class,id,fieldMap);
    }
    //删除用户
    public boolean deleteCustomer(long id){
        return DatabaseHelper.deleteEntity(Customer.class,id);
    }

    public static void main(String[] args) throws IOException {
        System.out.println(new CustomerService().getCustomer(1));
    }
}
